******************************************************************************************************************
*		
*		Tile: Political Agency, Election Quality, and Corruption
*
*		Authors: Nelson Ruiz-Guarin and Miguel R. Rueda
* 
*		Description: It generates Table 2 in appendix 
*
******************************************************************************************************************

use "C:\Users\mrueda\Documents\Emory\Papers\Corruption\Data\Colombia\replication_data.dta", clear
cd "C:\Users\mrueda\Documents\Emory\Papers\Corruption\results"

*Stata 14.0



xtset muni_code year



*Remember to udpate the command first.

*net install rdrobust, from(https://sites.google.com/site/rdpackages/rdrobust/stata) replace

*Analysis of the Dataset:

replace wage_mayor_upper_mw=floor(wage_mayor_upper_mw)

sort muni_code year

by muni_code: gen lag_rural_pop_t = rural_pop_t[_n-1]

by muni_code: gen lag_q_education = q_education[_n-1]

by muni_code: gen lag_population = population[_n-1]

*sum y_mw if year == 2003 | year == 2007

global controls y_mw lown_resources  wage_mayor_upper_mw margin_index2 ///
larmed_actor lag_population lag_rural_pop_t  lag_q_education

*

global fiscal y_mw lown_resources  wage_mayor_upper_mw 

global socioeconomic margin_index2 larmed_actor lag_population  lag_rural_pop_t ///
lag_q_education

global char comeback sanc_before any_demand

describe $controls

describe $fiscal

describe $socioeconomic 

cap erase "table_bal_rep_2.tex"

*************

*Definition of variables.

*************

texdoc init table_bal_rep_2, force

tex \begin{tabular}{l c c c c c c c}

tex \toprule[1.5pt]

tex \multicolumn{1}{c}{\textbf{Dependent variable}} & \textbf{Mean} & \parbox[c][1.3cm]{3cm}{\centering \textbf{\\ Standard \\ Deviation \\ }} & \textbf{Priv. fund won} 

tex &  \textbf{Std. Error.} & \textbf{Obs} & \textbf{Bandwidth} & \textbf{P-value} \\ \hline

tex  \\

***************

* Panel A

***************

tex \multicolumn{6}{l}{\textit{Panel A. Fiscal Covariates}}\\

foreach var of global fiscal {

    if "`var'"=="y_mw" {

        global description "Discretionary revenue"

    }

    if "`var'"=="lown_resources" {

        global description "Local revenue (t-1)"

    }

    if "`var'"=="wage_mayor_upper_mw" {

        global description "Mayor's salary"

    }

    

* Years

quietly sum `var' if year == 2003 | year == 2007

    local mean: di %12.3f r(mean)

    local sd: di %12.3f r(sd) 

    rdrobust `var' forcing if year == 2003 | year == 2007, all bwselect(mserd)

    local bw: di %12.3f `e(h_l)'

*   local bw = round(`e(h_l)',0.001)

    local ser = round(`e(se_tau_rb)',0.001)

    local N = `e(N_h_l)'+`e(N_h_r)'

    scalar p_val = e(pv_rb)

    scalar list p_val

    local pval = round(`e(pv_rb)',0.001)

    local beta = round(`e(tau_bc)',0.001)

    if p_val<=0.01 {

        local beta = "`beta'" + "***"

    }

    else if p_val<=0.05 {

        local beta = "`beta'" + "**"

    }

    else if p_val<=0.1 {

        local beta = "`beta'" + "*" 

    }   

    else {

        local beta = "`beta'"

    }

                

tex \ ${description} & `mean' & `sd' & `beta' & `ser' & `N' & `bw' & `pval' \\

}

tex \\

***************

* Panel B

***************

tex \multicolumn{6}{l}{\textit{Panel B. Socioeconomic Characteristics}}\\

foreach var of global socioeconomic {

    if "`var'"=="margin_index2" {

        global description "Avg. Margin of victory"

    }

    if "`var'"=="larmed_actor" {

        global description "Armed group (t-1)"

    }

    if "`var'"=="lag_population" {

        global description "Population (t-1)"

    }

    if "`var'"=="lag_rural_pop_t" {

        global description "Rural Population (t-1)"

    }

    if "`var'"=="lag_q_education" {

        global description "Underperforming schools (t-1)"

    }

    

* Years

quietly sum `var' if year == 2003 | year == 2007

    local mean: di %12.3f r(mean)

    local sd: di %12.3f r(sd) 

    rdrobust `var' forcing if year == 2003 | year == 2007, all bwselect(mserd)

    local bw: di %12.3f `e(h_l)'

*   round(`e(h_l)',0.001)

    local ser = round(`e(se_tau_rb)',0.001)

    local N = `e(N_h_l)'+`e(N_h_r)'

    scalar p_val = e(pv_rb)

    scalar list p_val

    local pval: di %12.3f `e(pv_rb)'

    local beta = round(`e(tau_bc)',0.001)

    if p_val<=0.01 {

        local beta = "`beta'" + "***"

    }

    else if p_val<=0.05 {

        local beta = "`beta'" + "**"

    }

    else if p_val<=0.1 {

        local beta = "`beta'" + "*" 

    }   

    else {

        local beta = "`beta'"

    }

                

tex \ ${description} & `mean' & `sd' & `beta' & `ser' & `N' & `bw' & `pval' \\

}

tex \\

***************

* Panel C Mayor characteristics

***************

tex \multicolumn{6}{l}{\textit{Panel C. Mayor characteristics}}\\

foreach var of global char {

*   if "`var'"=="ilegal" {

*       global description "Mayor registered ilegally to vote"

*   }

    if "`var'"=="comeback" {

        global description "Mayor held office before"

    }

    if "`var'"=="sanc_before" {

        global description "Mayor had sanctions before"

    }

    if "`var'"=="any_demand" {

        global description "Mayor was involved in a lawsuit"

    }

    

* Years

quietly sum `var' if year == 2003 | year == 2007

    local mean: di %5.3f r(mean)

    local sd: di %5.3f r(sd) 

    rdrobust `var' forcing if year == 2003 | year == 2007, all bwselect(mserd)

    local bw: di %12.3f `e(h_l)'

    local ser = round(`e(se_tau_rb)',0.001)

    local N = `e(N_h_l)'+`e(N_h_r)'

    scalar list p_val

    local pval: di %12.3f `e(pv_rb)'

*   local pval = round(`e(pv_rb)',0.001)

    local beta = round(`e(tau_bc)',0.001)

    if p_val<=0.01 {

        local beta = "`beta'" + "***"

    }

    else if p_val<=0.05 {

        local beta = "`beta'" + "**"

    }

    else if p_val<=0.1 {

        local beta = "`beta'" + "*" 

    }   

    else {

        local beta = "`beta'"

    }

                

tex \ ${description} & `mean' & `sd' & `beta' & `ser' & `N' & `bw' & `pval' \\

}

tex \\

tex \midrule[1 pt]

tex \\

tex \multicolumn{8}{l}{\footnotesize{\parbox{25cm}{\textbf{Notes:} Each coefficient reports RDD estimates 

tex of the effect of a having an additional voting booth, using Calonico et al. (2014) optimal bandwidths, bias correction, 

tex and robust standard errors, with linear local polynomials and triangular kernels.}}} \\

tex 

tex \end{tabular}

texdoc close
